//
//  oneselfInterfaceViewController.m
//  INAlienLand
//
//  Created by dllo on 15/6/29.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "oneselfInterfaceViewController.h"
#import "myEnterViewController.h"
#import "MyEnterTableViewCell.h"

#define WIDTH self.view.frame.size.width
#define HEIGHT self.view.frame.size.height
@interface oneselfInterfaceViewController ()<UITableViewDelegate,UITableViewDataSource>

//@property(nonatomic,retain)UIButton *WeChatButton;
//
//@property(nonatomic,retain)UIButton *MicroblogButton;
//
//@property(nonatomic,retain)UIButton *QQButton;

@property (nonatomic, retain) UITableView *mytableView;

@property (nonatomic, retain) NSMutableArray *arr;
@property (nonatomic,retain) UIView *leftView;
@property (nonatomic,retain) UIView *rightView;
@property (nonatomic,assign) BOOL isSlect;
@property (nonatomic,retain) UITableView *onesetable;

@end

@implementation oneselfInterfaceViewController

- (void)dealloc
{
    [_arr release];
    [_mytableView release];
    [super dealloc];
}

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.arr = [NSMutableArray arrayWithObjects:@"我的收藏", nil];
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    

   

    self.title = @"我的";
    
    UIImageView *myimageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height / 3)];
    myimageView.image = [UIImage imageNamed:@"旅途"];
    [self.view addSubview:myimageView];
    [myimageView release];
    
    self.mytableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT  - 64 - 49) style:UITableViewStylePlain];
    self.mytableView.dataSource = self;
    self.mytableView.delegate = self;
    self.mytableView.rowHeight = HEIGHT/9;
    [self.view addSubview:self.mytableView];
    [_mytableView release];
    
    self.mytableView.tableHeaderView = myimageView;
    


    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT/12)];

    

    view.backgroundColor = [UIColor redColor];
    
    [self.view addSubview:view];
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];

    button.frame = CGRectMake(10, 10, WIDTH-20, HEIGHT/12-20);

    [button setTitle:@"清除缓存" forState:UIControlStateNormal];
    [button addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:button];
    
    
    self.mytableView.tableFooterView = view;
    [view release];
    
    //self.navigationItem.rightBarButtonItem = self.editButtonItem;



    }





    





- (void)click:(UIButton *)button{
    
    
    NSString *title = NSLocalizedString(@"提示", nil);
    NSString *message = NSLocalizedString(@"是否清除缓存?", nil);
    NSString *cancelButtonTitle = NSLocalizedString(@"取消", nil);
    NSString *otherButtonTitle = NSLocalizedString(@"确定", nil);
    
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];



    //取消
     UIAlertAction *cancel =[UIAlertAction actionWithTitle:cancelButtonTitle style:UIAlertActionStyleCancel
                                                  handler:^(UIAlertAction *action) {
                                                      
                                                      
                                                  }];
    [alertController addAction:cancel];
    //确定,在里面删除缓存
    UIAlertAction *otherAction = [UIAlertAction actionWithTitle:otherButtonTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        
           NSFileManager *manager = [NSFileManager defaultManager];
            // 首先获取缓存文件的路径
            NSArray *cachesArr = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, 1, YES);
            NSString *cachesPath = cachesArr[0];
            NSLog(@"%@", cachesPath);
            [manager removeItemAtPath:cachesPath error:nil];

        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"缓存清除成功" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil , nil];
        [alert show];
    }];

  [alertController addAction:otherAction];
  [self presentViewController:alertController animated:YES completion:nil];

   


}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    
 
    return self.arr.count;
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    myEnterViewController *enterview = [[myEnterViewController alloc]init];
    [self.navigationController pushViewController:enterview animated:YES];
    [enterview release];
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

        static NSString *reuse = @"reuse";
       MyEnterTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse];
        if (!cell) {
            cell = [[MyEnterTableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:reuse];
        }
       cell.label.text = self.arr[indexPath.row];
        
        return cell;

    }
    






- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
\




/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
